package com.link2room.ironhide.service.impl;

import com.link2room.common.service.ICommonService;
import com.link2room.common.util.StringUtil;
import com.link2room.enums.exception.IronhideSysExceptionEnum;
import com.link2room.ironhide.entity.L2RHotelBaseinfo;
import com.link2room.ironhide.entity.L2RHotelPicture;
import com.link2room.ironhide.exception.IronhideException;
import com.link2room.ironhide.service.IHotelBaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by sss on 2016/11/11.
 */
@Service("hotelBaseService")
public class HotelBaseServiceImpl implements IHotelBaseService {
    @Resource
    private ICommonService commonService;

    @Override
    @Transactional
    public void saveOrUpdateHotelInfo(L2RHotelBaseinfo hotelBaseInfo, L2RHotelPicture bigHotelPic, List<L2RHotelPicture> hotelPictureList)throws Exception{
        commonService.saveOrUpdate(hotelBaseInfo);
        if(StringUtil.isNotBlank(hotelBaseInfo.getLhotelCode())){
            L2RHotelPicture queryL2RHP=new L2RHotelPicture();
            queryL2RHP.setLhotelGroupCode(hotelBaseInfo.getLhotelGroupCode());
            queryL2RHP.setLhotelCode(hotelBaseInfo.getLhotelCode());
            commonService.deleteAllEQ(L2RHotelPicture.class,queryL2RHP);
            if(bigHotelPic!=null){
                commonService.saveOrUpdate(bigHotelPic);
            }
            if(hotelPictureList!=null){
                commonService.saveOrUpdateList(hotelPictureList);
            }
        }else {
            throw new IronhideException(IronhideSysExceptionEnum.HOTELS_NOT_EXIT);
        }
    }


}
